/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin		 	*/
/*	Project:	GlbRtbEng-1.0.0			*/
/*	Author:		gong_libin			*/
/*	Date:		2016_06_26			*/
/*	File:		GlbRtbUtil.h			*/
/********************************************************/

#ifndef	_GLBRTBUTIL_H
#define	_GLBRTBUTIL_H

#include "GlbRtbDefs.h"
#include "GlbRtbIdxs.h"
#include "GlbRtbMems.h"

#define	GLB_RU_SHM			999999999ul

#define	GLB_RU_RDS			const_cast<char*>("REDS")
#define	GLB_RU_RST			const_cast<char*>("REST")
#define	GLB_RU_ADV			const_cast<char*>("ADVS")
#define	GLB_RU_ARE			const_cast<char*>("AREA")
#define	GLB_RU_LOG			const_cast<char*>("LOGS")
#define	GLB_RU_DEV			const_cast<char*>("DEVID")
#define	GLB_RU_SLP			const_cast<char*>("SLEEP")
#define	GLB_RU_GLB			const_cast<char*>("GLOBAL")
#define	GLB_RU_CFG			const_cast<char*>("CONFIG")

#define	GLB_RU_DRN			const_cast<char*>("\r\n\r\n")
#define	GLB_RU_200			const_cast<char*>("HTTP/1.1 200 OK")
#define	GLB_RU_CTL			const_cast<char*>("Content-Length: ")

#define	GLB_RU_SET(K, V)			do {			\
	if ('\0' != V[0]) {					\
		(pstKv + *pusTotal)->m_ucKey = K;		\
		(pstKv + *pusTotal)->m_iLength = strlen(V);	\
		(pstKv + *pusTotal)->m_puszValue = (UCHAR*)V;	\
		(*pusTotal) ++;					\
	}							\
} while (0)

void GlbRtbUtilSig();
void GlbRtbUtilKernel();
void GlbRtbUtilConfShow();
void GlbRtbUtilQuit(int iSignal);
int GlbRtbUtilConfLoad(char* pszConf);

int GlbRtbUtilRwLockNew();
void GlbRtbUtilRwLockDel();

int GlbRtbUtilCreateAll();
int GlbRtbUtilAttachAll();
int GlbRtbUtilUpdateAll();
int GlbRtbUtilCreateAdvs();
int GlbRtbUtilCreateArea();
int GlbRtbUtilAttachAdvs();
int GlbRtbUtilAttachArea();

void GlbRtbUtilCompare();
void GlbRtbUtilAdmin(char* pszHttp);
void GlbRtbUtilReqPrint(GLBRTBREQ_S* pstReq);
void GlbRtbUtilResPrint(GLBRTBRES_S* pstRes);
void GlbRtbUtilReqInput(GLBRTBREQ_S* pstReq, GlbNet::GLBPROKV_S* pstKv, USHORT usTotal);
void GlbRtbUtilResInput(GLBRTBRES_S* pstRes, GlbNet::GLBPROKV_S* pstKv, USHORT* pusTotal);

#endif /* _GLBRTBUTIL_H */
